/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sqlserver;

import Database.Table;
import java.awt.Component;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author PHAMDANH
 */
public class CheckboxCellRenderer extends JCheckBox implements TableCellRenderer
{
    private Table table;
    public CheckboxCellRenderer(String[] items, Table table) 
    {
        this.table = table;
    }

    @Override
    public Component getTableCellRendererComponent(JTable jtable, Object value, boolean isSelected, 
                                                   boolean hasFocus, int row, int column) 
    {
        if(value!=null)
        {            
            if(table.getColumns().size()>row)
                table.getColumns().get(row).setAllowNull((Boolean)value);     
            this.setSelected((Boolean)value);        
        }
        else
            this.setSelected(false);          
        return this;
    }
   

}
